# 4.6 Card Recognition ## 4.6.1 Algorithm ![15](./media/15.png) It can identify whether there are corresponding traffic cards in the image. If yes, it will return information including the coordinates, size, and label values of the cards. -------- ## 4.6.2 Classification Label | Label | Definition | Pic | | :---: | :---------: | :---------------------: | | 1 | go forward | ![007](./media/007.png) | | 2 | turn left | ![001](./media/001.png) | | 3 | turn right | ![002](./media/002.png) | | 4 | turn around | ![004](./media/004.png) | | 5 | stop | ![003](./media/003.png) | | 6 | green light | ![009](./media/009.png) | | 7 | red light | ![005](./media/005.png) | | 8 | speed 40 | ![008](./media/008.png) | | 9 | speed 60 | ![010](./media/010.png) | | 10 | speed 80 | ![006](./media/006.png) | Note: The algorithm can recognize multiple cards simultaneously. The card can still be recognized within a certain rotation, deflection and pitch angle. When using, please make the card face the camera as directly as possible for better recognition effect. ------------ ## 4.6.3 Test Code 1. In the code start-up, set the serial port baud rate to `9600`, and then set the communication mode of the AI vision module to `I2C`, and finally set it to run in `Card` mode. ![a54](./media/a54.png) 2. The if block determines the number of detections. Only when the number of detections is greater than 0 will the data be output. Note to choose `Card`. 3. Loop through the result quantity. When multiple cards are detected, it will loop multiple times and then use a variable on the parameter group. After each loop print, the variable adds by one. In this way, the information of cards can be printed (Note: Set the mode of the returned data to “Card”). **Complete code:** ![a55](./media/a55.png) ## 4.6.4 Test Result After uploading the code, the AI vision module will scan the area captured by the camera. If there is a card, it will recognize the card and print its coordinates(x,y), width(w) and height(h) in the serial monitor. ![](./media/a56.png) ## 4.6.5 Extension Gameplay **Color picker** - **Game rule:** Rotate the card (to the right/left) to change WS2812 light colors. For example, the normal sequence of lights is: red > green > blue > yellow > purple, etc., yet we can adjust them by turning the card. Suppose the current color is red, and we rotate the card to the right to change it to green; rotate to the left to make it purple; in a loop. - **Practice:** After identifying the card, control the light by performing addition or subtraction on a variable.